home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
101-125
/
118
/
empire
/
src
/
source.zoo
/
cmd_general1.d
< prev
next >
Wrap
Text File
|
1987-12-02
|
14KB
|
567 lines
#include:util.g
#empire.g
#empfunc.g
/* variables needed by cmd_desig: */
SectorType_t Designation;
/* ************ */
proc cmd_change()void:
uint what, i;
[NAME_LEN] char name;
[25] char buf;
bool duplicate;
if reqChoice(&what, "name\epassword\ecountry\e",
"Change what (name/password/country): ") then
if what = 2 then
if reqCountry(&i, "Enter country to change to: ") then
if getPassword("Enter password: ",
&Country[i].c_password[0]) then
ThisCountryNumber := i;
ThisCountry := &Country[i];
pretend(resetTimer(), void);
ConvTime(CurrentTime(), &buf[0]);
if UsingSerial then
writeln();
writeln(&buf[0], " - changed to country ",
&ThisCountry*.c_name[0]);
putPrompt();
fi;
writeln(LogChannel; &buf[0], " - changed to country ",
&ThisCountry*.c_name[0]);
telegramCheck();
else
writeln(Chout; "- country not changed");
fi;
fi;
else
if getPassword("Enter your current password: ",
&ThisCountry*.c_password[0]) then
if what = 0 then
write(Chout; "Enter new country name: ");
if readLine(&name[0], NAME_LEN) then
duplicate := false;
for i from 0 upto World.w_currCountries - 1 do
if CharsEqual(&Country[i].c_name[0], &name[0]) and
i ~= ThisCountryNumber then
duplicate := true;
fi;
od;
if duplicate then
err("that name is already in use");
else
ThisCountry*.c_name := name;
news(n_name_change, ThisCountryNumber, DEITY);
fi;
fi;
else
pretend(getVerifiedPassword("Enter new password: "), void);
fi;
else
writeln(Chout;);
fi;
fi;
fi;
corp;
proc cmd_translate()void:
int r, c;
uint country;
if ThisCountryNumber = DEITY then
if reqCountry(&country, "Country to translate sector from? ") and
doSkipBlanks() and
reqSector(&r, &c, "Sector in that country to translate? ") then
ThisCountry := &Country[country];
writeln(Chout; &ThisCountry*.c_name[0], " sector ", r, ',', c,
" is at absolute ", transRow(r), ',', transCol(c));
ThisCountry := &Country[DEITY];
fi;
else
err("only god can use this command");
fi;
corp;
proc cmd_country()void:
uint i;
writeDate(CurrentTime());
writeln(Chout;);
writeln(Chout;
"\# last access time BTU's status country name");
writeln(Chout;
"--------------------------------------------------------------");
for i from 0 upto World.w_currCountries - 1 do
write(Chout; i, ' ');
writeDate(Country[i].c_last);
writeln(Chout; " [", Country[i].c_timer : 3, "] [",
Country[i].c_btu : 2, "] ",
case Country[i].c_status
incase cs_deity:
"DEITY "
incase cs_active:
"Active "
incase cs_dead:
"Destroyed"
incase cs_quit:
"Resigned "
incase cs_idle:
"Idle "
default:
"*fucked*"
esac,
' ',
&Country[i].c_name[0]
);
od;
writeln(Chout;);
corp;
/*
* doCensus - part of cmd_census
*/
proc doCensus(int r, c; Sector_t s)void:
[9] char DELIVERY = ('0','1','2','3','4','5','6','7',' ');
writeln(Chout;
if s.s_price = 0 then ' ' else '$' fi,
if s.s_checkPoint = 0 then ' ' else '*' fi,
DELIVERY[s.s_direction[it_civilians]],
DELIVERY[s.s_direction[it_military]],
DELIVERY[s.s_direction[it_shells]],
DELIVERY[s.s_direction[it_guns]],
DELIVERY[s.s_direction[it_planes]],
DELIVERY[s.s_direction[it_ore]],
DELIVERY[s.s_direction[it_bars]],
if s.s_defender = NO_DEFEND then ' ' else '%' fi,
' ', SectorChar[s.s_type],
" ", s.s_efficiency : 3,
' ', s.s_iron : 3,
" ", s.s_gold : 3,
' ', s.s_mobility : 3,
' ', readQuan(s, it_civilians) : 4,
' ', readQuan(s, it_military) : 3,
' ', readQuan(s, it_shells) : 4,
' ', readQuan(s, it_guns) : 4,
' ', readQuan(s, it_planes) : 3,
' ', readQuan(s, it_ore) : 4,
' ', readQuan(s, it_bars) : 3,
' ', s.s_production : 3,
" ", r : 3, ',', c
);
corp;
proc cmd_census()void:
if reqSectors("Enter sectors specification for census: ") then
writeln(Chout;
" cmsgpob des eff min gold mob civl mil sh gun pl ore bar prod");
writeln(Chout;
"-------------------------------------------------------------------");
if scanSectors(doCensus) = 0 then
err("no sectors matched");
else
writeln(Chout;);
fi;
fi;
corp;
/*
* isHead - return 'true' if the sector is a bridge head.
*/
proc isHead(int r, c)bool:
Sector_t s;
readSector(r, c, s);
s.s_type = s_bridgeHead and s.s_efficiency >= 20
corp;
/*
* zapSpan -
* waste a bridge span - also used in other places.
*/
proc zapSpan(Sector_t s)void:
ItemType_t it;
s.s_type := s_water;
s.s_owner := DEITY;
s.s_efficiency := 0;
s.s_mobility := 0;
s.s_defender := NO_DEFEND;
for it from it_first upto it_last do
s.s_quantity[it] := 0;
od;
writeln(Chout; "Skreeetch! SPLASH!!!!");
corp;
/*
* checkCollapse -
* see if a given sector is an unsupported bridge span - smash it!!!!
*/
proc checkCollapse(int r, c)void:
Sector_t s;
readSector(r, c, s);
if s.s_type = s_bridgeSpan and
not isHead(r - 1, c) and
not isHead(r, c - 1) and
not isHead(r, c + 1) and
not isHead(r + 1, c) then
zapSpan(s);
writeSector(r, c, s);
fi;
corp;
/*
* collapseSpans -
* A bridge head or bridge span is being torn down.
* Collapse any bridge spans that depend on it for support.
*/
proc collapseSpans(int r, c)void:
checkCollapse(r - 1, c);
checkCollapse(r, c - 1);
checkCollapse(r, c + 1);
checkCollapse(r + 1, c);
corp;
/*
* doDesignate - part of cmd_designate
*/
proc doDesignate(int r, c; Sector_t s)void:
Sector_t s1;
SectorType_t oldDesig;
ItemType_t it;
oldDesig := s.s_type;
if ThisCountryNumber = DEITY or
oldDesig ~= s_mountain and oldDesig ~= s_bridgeSpan and
oldDesig ~= s_water then
if r = 0 and c = 0 and ThisCountryNumber ~= DEITY then
err("can't redesignate your current capital");
else
s1 := s;
if oldDesig = s_sanctuary then
writeln(Chout;"You are breaking sanctuary!!!");
news(n_broke_sanctuary, ThisCountryNumber, DEITY);
elif s.s_efficiency ~= 0 and oldDesig ~= s_wilderness and
Designation ~= oldDesig then
if Designation = s_highway then
write(Chout; "Paving over ");
else
write(Chout; "Tearing down ");
fi;
writeln(Chout; s.s_efficiency, "% efficient ",
getDesigName(oldDesig), " at ", r, ',', c);
fi;
if oldDesig = s_exchange and Designation ~= s_exchange or
oldDesig ~= s_exchange and Designation = s_exchange then
for it from it_first upto it_last do
s1.s_direction[it] := NO_DELIVER;
s1.s_threshold[it] := 0;
od;
fi;
s1.s_type := Designation;
for it from it_first upto it_last do
writeQuan(s1, it, readQuan(s, it));
od;
if Designation ~= oldDesig then
s1.s_efficiency := 0;
s1.s_production := 0;
fi;
writeSector(r, c, s1);
if oldDesig = s_bridgeHead and Designation ~= s_bridgeHead then
collapseSpans(r, c);
fi;
if Designation = s_capital and ThisCountryNumber ~= DEITY then
ThisCountry*.c_centerRow := transRow(r);
ThisCountry*.c_centerCol := transCol(c);
fi;
fi;
fi;
corp;
proc cmd_designate()bool:
uint count;
if reqSectors("Enter sectors specification for designate: ") and
doSkipBlanks() and
reqDesig(&Designation, "Enter type to designate: ") then
if (Designation = s_mountain or Designation = s_water or
Designation = s_sanctuary) and ThisCountryNumber ~= DEITY then
err("Only God can make a mountain, ocean or sanctuary");
false
else
count := scanSectors(doDesignate);
if count = 0 then
err("no sectors matched");
elif count > 1 then
writeln(Chout; count, " sectors designated");
fi;
true
fi
else
false
fi
corp;
/*
* doCheckpoint - part of cmd_checkpoint
*/
proc doCheckpoint(int r, c; Sector_t s)void:
channel output text promptChan;
[100] char buf;
int n;
open(promptChan, &buf[0]);
write(promptChan;
"Enter new checkpoint code for sector ", r, ',', c, ": ");
close(promptChan);
if reqNumber(&n, &buf[0]) then
if n < -128 or n > 127 then
err("invalid checkpoint code - not changed");
else
s.s_checkPoint := n;
writeSector(r, c, s);
fi;
else
err("checkpoint code not changed");
fi;
corp;
proc cmd_checkpoint()bool:
if reqSectors("Checkpoint which sectors? ") then
skipBlanks();
if getPassword("Enter your password to verify: ",
&ThisCountry*.c_password[0]) then
if scanSectors(doCheckpoint) = 0 then
err("no sectors matched");
fi;
true
else
writeln(Chout; " - no sectors checkpointed");
false
fi
else
false
fi
corp;
proc cmd_update()bool:
Sector_t s;
*char p, q;
uint count;
int r, c, top, bottom, left, right, minRow, maxRow, minCol, maxCol;
bool doit, wholeWorld;
doit := true;
wholeWorld := false;
if InputPtr* = '\e' then
top := - (World.w_rows / 2);
bottom := (World.w_rows - 1) / 2;
left := - (World.w_columns / 2);
right := (World.w_columns - 1) / 2;
wholeWorld := true;
elif not getBox(&top, &bottom, &left, &right) then
doit := false;
fi;
if doit then
skipBlanks();
if InputPtr* ~= '\e' then
p := InputPtr;
skipWord();
q := InputPtr;
skipBlanks();
q* := '\e';
if CharsEqual(p, "terse") then
QuietUpdate := true;
elif CharsEqual(p, "verbose") then
VerboseUpdate := true;
fi;
fi;
count := 0;
minRow := 1000;
maxRow := -1000;
minCol := 1000;
maxCol := -1000;
for r from top upto bottom do
for c from left upto right do
accessSector(r, c, s);
if s.s_owner = ThisCountryNumber then
count := count + 1;
if r < minRow then
minRow := r;
fi;
if r > maxRow then
maxRow := r;
fi;
if c < minCol then
minCol := c;
fi;
if c > maxCol then
maxCol := c;
fi;
fi;
od;
od;
if wholeWorld then
minRow := minRow - 1;
maxRow := maxRow + 1;
minCol := minCol - 1;
maxCol := maxCol + 1;
ThisCountry*.c_realms[0].r_top := minRow;
ThisCountry*.c_realms[0].r_bottom := maxRow;
ThisCountry*.c_realms[0].r_left := minCol;
ThisCountry*.c_realms[0].r_right := maxCol;
ThisCountry*.c_sectorCount := count;
writeln(Chout; "Your realm 0 (\#0) is ", minRow, ':', maxRow, ',',
minCol, ':', maxCol, " and consists of ", count,
" sectors.");
fi;
true
else
false
fi
corp;
proc cmd_nation()void:
Sector_t s;
uint i;
readSector(0, 0, s);
write(Chout; "Status of ", &ThisCountry*.c_name[0], " at ");
writeDate(CurrentTime());
writeln(Chout; ": ");
writeln(Chout;);
writeln(Chout; "Number of sectors: ", ThisCountry*.c_sectorCount);
writeln(Chout; "Cash on hand: ", ThisCountry*.c_money);
writeln(Chout; "Technology level: ", ThisCountry*.c_techLevel);
i := getTechFactor(ThisCountryNumber);
writeln(Chout; "Technology factor: ", i / 100, '.', i % 100 : -2);
writeln(Chout; "Research level: ", ThisCountry*.c_resLevel);
i := calcPlagueFactor(s);
writeln(Chout; "Plague factor in capital: ", i / 100, '.', i % 100 : -2);
write(Chout; "Realms: ");
for i from 0 upto REALM_MAX - 1 do
write(Chout; '\#', i, ": ",
ThisCountry*.c_realms[i].r_top, ':',
ThisCountry*.c_realms[i].r_bottom, ',',
ThisCountry*.c_realms[i].r_left, ':',
ThisCountry*.c_realms[i].r_right, ' ');
od;
writeln(Chout;);
writeln(Chout;);
for i from 1 upto World.w_currCountries - 1 do
if i ~= ThisCountryNumber and Country[i].c_status = cs_active then
if ThisCountry*.c_relations[i] ~= r_neutral then
writeln(Chout; &ThisCountry*.c_name[0], " is ",
case ThisCountry*.c_relations[i]
incase r_allied:
"allied"
incase r_war:
"at war"
esac,
" with ", &Country[i].c_name[0], '.');
fi;
if Country[i].c_relations[ThisCountryNumber] ~= r_neutral then
writeln(Chout; &Country[i].c_name[0], " is ",
case Country[i].c_relations[ThisCountryNumber]
incase r_allied:
"allied"
incase r_war:
"at war"
esac,
" with ", &ThisCountry*.c_name[0], '.');
fi;
fi;
od;
writeln(Chout;);
corp;
/*
* doContract - part of cmd_contract
*/
proc doContract(int r, c; Sector_t s)void:
uint price;
if s.s_owner = ThisCountryNumber and
(s.s_type = s_industry or
s.s_type = s_defense or
s.s_type = s_airport or
s.s_type = s_harbour or
s.s_type = s_bridgeHead or
s.s_type = s_ironMine or
s.s_type = s_goldMine or
s.s_type = s_research or
s.s_type = s_technical) then
price :=
case random(100)
incase 0..1:
random(40) + 1
incase 2..97:
random(60) + 40
incase 98..99:
random(140) + 100
esac * World.w_contractScale / 100;
writeln(Chout; "You are offered $", price * 5 / 100,
'.', price * 5 % 100 : -2,
" for the production of sector ", r, ',', c);
if ask("Do you accept? ") then
s.s_price := price;
else
s.s_price := 0;
fi;
writeSector(r, c, s);
fi;
corp;
proc cmd_contract()bool:
if reqSectors("Sector(s) to contract: ") then
if scanSectors(doContract) = 0 then
err("no sectors matched");
fi;
true
else
false
fi
corp;
proc cmd_realm()void:
int top, bottom, left, right, realm;
if getNumber(&realm) then
if realm < 0 or realm >= REALM_MAX then
err("invalid realm number");
else
skipBlanks();
if InputPtr* ~= '\e' then
if getBox(&top, &bottom, &left, &right) then
ThisCountry*.c_realms[realm].r_top := top;
ThisCountry*.c_realms[realm].r_bottom := bottom;
ThisCountry*.c_realms[realm].r_left := left;
ThisCountry*.c_realms[realm].r_right := right;
fi;
else
writeln(Chout; "Realm ", realm, " is ",
ThisCountry*.c_realms[realm].r_top, ':',
ThisCountry*.c_realms[realm].r_bottom, ',',
ThisCountry*.c_realms[realm].r_left, ':',
ThisCountry*.c_realms[realm].r_right, '.');
fi;
fi;
fi;
corp;